import { PAbyssR,uptime,bfbh } from './bh3G.js';
import * as path from 'path';
const defaultImagePath = './plugins/qiqi-plugin/resources/BH3/404.png';
const defaultImagePath1 = './plugins/qiqi-plugin/resources/BH3/405.png';
const png404 = path.resolve(defaultImagePath);
const png405 = path.resolve(defaultImagePath1);
const level1 = {
    0: "未战斗",
    1: "禁忌",
    2: "原罪Ⅰ",
    3: "原罪Ⅱ",
    4: "原罪Ⅲ",
    5: "苦痛Ⅰ",
    6: "苦痛Ⅱ",
    7: "苦痛Ⅲ",
    8: "红莲",
    9: "寂灭",
    "A": "红莲",
    "B": "苦痛",
    "C": "原罪",
    "D": "禁忌",
  };

const ABTA = {
    idValue: 0,
    score: 0,
    rank: 0,
    settled_cup_number: 0,
    cup_number: 0,
    abystarttiem: '未知时间',
    abylevel1: '未知等级',
    bossName: '未知BOSS',
    ABYAVA: [
        {
            icon_path: png404,
            star: png404
        },
        {
            icon_path: png404,
            star: png404
        },
        {
            icon_path: png404,
            star: png404
        }
    ],
    efava: png404,
    bossAvatar: png405
};

const BH3BF = {
    "bfrk": "未知",
    "bfae": "未知",
    "bfuptime":"未知",
    "bfekpc": "未知排名",
    "tlscore": "无得分",
    "bf": [
      {
        "elf": {
          "id": "404",
          "name": "无",
          "avatar": png404
        },
        "lineup": [
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          }
        ],
        "boss": {
          "id": "404",
          "name": "无",
          "avatar": png405
        },
        "score": "无得分"
      },
      {
        "elf": {
          "id": "404",
          "name": "无",
          "avatar": png404
        },
        "lineup": [
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          }
        ],
        "boss": {
          "id": "404",
          "name": "无",
          "avatar": png405
        },
        "score": "无得分"
      },
      {
        "elf": {
          "id": "404",
          "name": "无",
          "avatar": png404
        },
        "lineup": [
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          },
          {
            "icon_path": png404,
            "star": 404
          }
        ],
        "boss": {
          "id": "404",
          "name": "无",
          "avatar": png405
        },
        "score": "无得分"
      }
    ]
  }

const BH3GW = {
    score: "无得分",
    settle_time_second: '未知时间',
    cost_time: '未知时间',
    support_avatars: png404,
    assistant_extra_ite: png404, 
    mainavatar: {
      star: png404,
      icon_path: png404
    },
    supportavatars: [
      {
        icon_path: png404 
      },
      {
        icon_path: png404 
      }
    ],
    elf: {
      id: '114514',
      name: '未知',
      avatar: png404
    }
};

async function bh3P(abyssR) {
    if (!abyssR || typeof abyssR !== 'object') {
        console.error("深渊数据无效或为空");
        return { error: true, message: "无效的深渊数据" };
    }

    const abyssRR1 = await PAbyssR(abyssR);

    if (abyssRR1.error) {
        console.error("处理出错:", abyssRR1.message);
        return {
            idValue: abyssRR1.id123 || 0,
            abyssRR: abyssRR1 || {}
        };
    }

    const idValue = abyssRR1.id123 || 0;
    const abyssRR = abyssRR1 || {};

    const {
        score = 0,
        updated_time_second = 0,
        rank = 0,
        settled_cup_number = 0,
        cup_number = 0,
        level: abyssLevel = 0,
    } = abyssRR || {};

    const { name: bossName = '未知BOSS' } = abyssRR.boss || {};

    const ABYAVA = (abyssRR.lineup || []).map(character => ({
        icon_path: character.icon_path || '',
        star: character.star || ''
    }));

    const efava = abyssRR.elf && abyssRR.elf.local_avatar_path
        ? path.resolve(abyssRR.elf.local_avatar_path)
        : png404;

    const bossAvatar = abyssRR.boss && abyssRR.boss.local_avatar_path
        ? path.resolve(abyssRR.boss.local_avatar_path)
        : png405;

    const abystarttiem = updated_time_second
        ? uptime(updated_time_second)
        : '未知时间';

    const abylevel1 = level1[Number(abyssLevel)] || "未知等级";
    // console.log(abylevel1)

    return {
        idValue,
        score,
        rank,
        settled_cup_number,
        cup_number,
        abystarttiem,
        abylevel1,
        bossName,
        ABYAVA,
        efava,
        bossAvatar
    };
}



export {bh3P,ABTA,BH3BF,BH3GW};